/*
 * ConsoleOutput.java
 *
 * (C) Copyright 2005-2007 Pierre Salagnac
 * All rights reserved
 *
 * Created on 12 novembre 2007, 16:36
 */
package com.reimscopie.console ;

import java.io.* ;


/**
 * This class has the default output and the error output of the console.
 */
public class ConsoleOutput {
  
  // writers
  private PrintWriter out ;
  private PrintWriter err ;
  
  
  /**
   * Create a new instance with output writers.
   *
   * @param out The default output.
   * @param err The error output.
   */
  public ConsoleOutput(PrintWriter out,PrintWriter err) {
    
    this.out = out ;
    this.err = err ;
    
  }
  
  
  /**
   * Print a message in the default output.
   *
   * @param message The message to print.
   */
  public void print(String message) {
    print(message,false) ;
  }
  
  
  /**
   * Print a message in the default output.
   *
   * @param message The message to print.
   * @param line Put a new line character.
   */
  public void print(String message,boolean line) {
    
    // message
    out.print(message) ;
    
    // <CR>
    if (line)
      out.print(System.getProperty("line.separator")) ;
  }
  
  
  /**
   * Print a single character in the default output.
   *
   * @param c The character to print.
   */
  public void print(char c) {
    
    out.print(c) ;
    
  }
  
  
  /**
   * Print a new line in the default output.
   */
  public void println() {
    
    out.println() ;
    
  }
  
  
  /**
   * Print a message in the error output.
   *
   * @param message The message to print.
   */
  public void printError(String message) {
    printError(message,false) ;
  }
  
  
  /**
   * Print a message in the error output.
   *
   * @param message The message to print.
   * @param line Put a new line character.
   */
  public void printError(String message,boolean line) {
    
    // message
    err.print(message) ;
    
    // <CR>
    if (line)
      err.println() ;
  }
  
  
  /**
   * Trace an exception.
   *
   * @param th The error to trace.
   */
  public void printError(Throwable th) {
    
    th.printStackTrace(err) ;
    
  }
  
}
